package com.example.android.apis.graphics;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.Toast;

public class HelloGridView extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout vG = new LinearLayout(this);
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(-1, -1);
        vG.setLayoutParams(lp);
        setContentView(vG);
        GridView gridview = new GridView(this);
        ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(-1,-1);       
        gridview.setLayoutParams(p);
        gridview.setColumnWidth(90);
        gridview.setNumColumns(-1);
        gridview.setVerticalSpacing(10);
        gridview.setHorizontalSpacing(10);
        gridview.setStretchMode(2);
        gridview.setGravity(0x11);
        gridview.setAdapter(new ImageAdapter(this));

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }
}